﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Ocean.OceanFramework.WPF.Utility; 
using WPFLOBMVVM.ViewModel;

namespace WPFLOBMVVM.View
{
    /// <summary>
    /// Interaction logic for ApplicationMainWindow.xaml
    /// </summary>
    public partial class ApplicationMainWindow : Window
    {
        public ApplicationMainWindow()
        {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(ApplicationMainWindow_Closing);
        }

        public void RequestClose(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ApplicationMainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (this.DataContext != null)
            {
                //this ensures that if the user clicked the Close Form "X" or typed ALT-F4 
                //that a TextBox with an entry that has not completed will cause Data Bindings to update. 
                Helpers.UpdateFocusedField();
                // 
                e.Cancel = !((ApplicationMainWindowViewModel)this.DataContext).CanApplicationClose();
            }

        }
    }
}
